package ca.shojaei.mini_sat;

import java.util.*;

public class State {
	
	public static final int DEF_VAR  = 10;
	
	
	private HashMap<String, Integer> vars;
	private Vector<State> nexts;
	private int curVars = 0;
	private int stateName;
	private boolean visited = false;
	
	
	public State(HashMap<String, Integer> vars , int name)
	{
		if(vars != null)
			this.vars = vars;
		else
			throw new NullPointerException("var list is empty");
		
		nexts = new Vector<State>(DEF_VAR);
		
		this.stateName = name;
		curVars = vars.size();
		
	}
/*	
	public void addNextState(HashMap<String,Integer> var, int stateName)
	{
		if(var.size() != curVars || stateName == this.stateName)
			throw new  VarNotMatchException("Not matching total var");
		
		State temp = new State(var, stateName);
		
		this.nexts.add(temp);
		
	}
	*/
	
	public void addNextState(State s)
	{
		
		this.nexts.add(s);
		
	}
	

	public boolean hasNextState()
	{
		return !this.nexts.isEmpty();
	}
	
	public int getNextStateCount()
	{
		return this.nexts.size();
	}
	
	public int[] getVarNexts(String name)
	{
		int result[] = new int[this.curVars];
		
		for(int i = 0 ; i < this.nexts.size(); i++)
		{
			result[i] = this.nexts.get(i).getVar(name);
		}
		
		return result;
	}
	
	public int getVar(String name)
	{
		return this.vars.get(name);
	}
	
	

	public int getStateName()
	{
		return this.stateName;
	}
	
	public int[] getAllVariables()
	{
	
		Collection<Integer> temp = this.vars.values();
		int result[] = new int[temp.size()];
		Iterator<Integer> it = temp.iterator();
		for(int i = 0 ; i < temp.size(); i++)
		{
			result[i] = it.next();
		}
		return result;
	}
	
	
	public Vector<int[]> getAndVariables()
	{
		Collection<Integer> temp = this.vars.values();
		Vector<int[]> result = new Vector<int[]>();
		
		Iterator<Integer> it = temp.iterator();
		for(int i = 0 ; i < temp.size(); i++)
		{
			int temp1[] = new int[1];
			temp1[0] = it.next();
			
			result.add(temp1);
		}
		return result;
	}
	
	public Vector<State> getNexts()
	{
		return this.nexts;
	}
	public int[] getOrNexts(String name)
	{
		int [] result = new int[this.nexts.size()];
		for(int i = 0; i < this.nexts.size(); i++)
		{
			result[i] = this.nexts.get(i).getVar(name);
		}
		
		return result;
	}
	
	public int[][] getAndNexts(String name){
		
		int result [][] = new int[nexts.size()][1];
		for(int i = 0; i < this.nexts.size(); i++)
		{
			result[i][1] = this.nexts.get(i).getVar(name);
		}
		
		return result;
		
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}

	public boolean isVisited() {
		return visited;
	}
	
}
